#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

struct head
{
	int type;
	char mean[10];
};


struct user
{
	char name[10];
	char passwd[10];
};




int main()
{

	int sock = 0;
	int ret = 0;
	char buf[1024] = {0};

	struct sockaddr_in addr;
    memset(&addr,0,sizeof(addr));

	sock = socket(AF_INET,SOCK_DGRAM,0);
	if(sock == -1)
	{
		perror("sock");
		exit(-1);
	}

	addr.sin_family = AF_INET;
    addr.sin_port = 6868;
    addr.sin_addr.s_addr = inet_addr("192.168.0.156");

	ret = bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr));
	if(ret == -1)
	{
		perror("bind");
		exit(-1);
	}

	struct sockaddr_in cliaddr;
	memset(&cliaddr,0,sizeof(cliaddr));

	int len = sizeof(struct sockaddr);

	ret = recvfrom(sock,buf,1024,0,(struct sockaddr *)&cliaddr,&len);
	if(ret == -1)
	{
		perror("recvfrom");
		exit(-1);
	}

	struct head *p = (struct head *)buf;
	if(p->type == 1)
	{
		struct user *q = NULL;
		q = (struct user *)(buf + sizeof(struct head));
		printf("name is %s,password is %s\n",q->name,q->passwd);
	}

	
	close(sock);

	return 0;


}
